package org.orz.story.pms.biz.web.admin;

import io.swagger.annotations.ApiOperation;
import org.orz.cloud.common.result.ResultDTO;
import org.orz.cloud.common.result.ResultPageDTO;
import org.orz.story.pms.biz.model.req.*;
import org.orz.story.pms.biz.model.resp.ListRoleInfoResp;
import org.orz.story.pms.biz.model.resp.ListRoleWithGrantStatusResp;
import org.orz.story.pms.biz.service.PmsRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("admin/role")
public class AdminRoleController {
    @Autowired
    private PmsRoleService pmsRoleService;

    @PostMapping("listRoleInfo")
    @ApiOperation("分页查询角色列表")
    public ResultPageDTO<ListRoleInfoResp> listRoleInfo(@RequestBody ListRoleInfoReq req){
        return ResultPageDTO.restPage(pmsRoleService.listRoleInfo(req), ListRoleInfoResp.class);
    }

    @PostMapping("listRoleWithGrantStatus")
    @ApiOperation("查询角色列表-包含是否分配")
    public ResultDTO<List<ListRoleWithGrantStatusResp>> listRoleWithGrantStatus(@RequestBody ListRoleWithGrantStatusReq req){
        return ResultDTO.success(pmsRoleService.listRoleWithGrantStatus(req));
    }

    @ApiOperation("添加角色")
    @PostMapping("addRole")
    public ResultDTO<Boolean> addRole(@RequestBody AddRoleReq req){
        pmsRoleService.addRole(req);
        return ResultDTO.success();
    }

    @ApiOperation("修改角色")
    @PostMapping("updateRole")
    public ResultDTO<Boolean> updateRole(@RequestBody UpdateRoleReq req){
        pmsRoleService.updateRole(req);
        return ResultDTO.success();
    }

    @ApiOperation("删除角色")
    @PostMapping("deleteRole")
    public ResultDTO<Boolean> deleteRole(@RequestBody DeleteRoleReq req){
        pmsRoleService.deleteRole(req);
        return  ResultDTO.success();
    }

    @ApiOperation("分配角色")
    @PostMapping("grantRole")
    public ResultDTO<Boolean> grantRole(@RequestBody GrantRoleReq req){
        pmsRoleService.grantRole(req);
        return ResultDTO.success();
    }


}
